/*
 *  Copyright 2007 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.persistence.core;

import com.blandware.atleap.common.util.PartialCollection;
import com.blandware.atleap.common.util.QueryInfo;
import com.blandware.atleap.model.core.Localizable;
import com.blandware.atleap.model.core.Sequence;

/**
 * <p>DAO for sequence.</p>
 * <p><a href="SequenceDAO.java.html"><i>View Source</i></a></p>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version : $Revision: 1.2 $ : 2007/12/17 13:38:25 $
 */
public interface SequenceDAO extends DAO {

	// ~ CRUD Methods ================================================================

	/**
	 * Creates new sequence.
	 *
	 * @param sequence    Value object that represents what sequence must
     *                    be created
	 * @param localizable Localizable to associate sequence with
	 * @return ID of created sequence
	 */
	public Long createSequence(Sequence sequence, Localizable localizable);

	/**
	 * Retrieves sequence with specified ID.
	 *
	 * @param sequenceId   ID to search by
	 * @return Sequence or null if no sequence with specified ID exists in database
	 */
	public Sequence retrieveSequence(Long sequenceId);

	/**
	 * Updates sequence.
	 *
	 * @param sequence Sequence to update
     * @param localizable Localizable to associate field with
	 */
	public void updateSequence(Sequence sequence, Localizable localizable);

	/**
	 * Deletes sequence.
	 *
	 * @param sequence Sequence to delete
	 */
	public void deleteSequence(Sequence sequence);

	// ~ Additional methods ================================================================

	/**
	 * Retrieves filtered/sorted collection of sequences.
	 *
	 * @param queryInfo Object that contains information about how to filter and sort data
	 * @return Collection of sequences
	 */
	public PartialCollection listSequences(QueryInfo queryInfo);

	/**
	 * Searches for duplicates. Returns true if there is one or more sequences
     * with another ID, but which have same values from some set (e.g.
     * identifier and localizable).
	 *
	 * @param sequence     Sequence to find duplicates for
	 * @param ownerId      ID of owner Localizable
	 * @return whether this sequence has duplicates
	 */
	public boolean hasDuplicates(Sequence sequence, Long ownerId);

	// ~ Finders ================================================================

	/**
	 * Finds sequence by identifier and layout definition.
	 *
	 * @param identifier Identifier of sequence to search by
	 * @param definition Struts tile definition on which localizable is based
	 * @return Sequence or null if nothing was found
	 */
	public Sequence findSequenceByLayoutDefinition(String identifier, String definition);

	/**
	 * Finds sequence by page URI and identifier.
	 *
	 * @param identifier Identifier of sequence to search by
	 * @param uri        URI of page to which sequence belongs
	 * @return Sequence or null if nothing was found
	 */
	public Sequence findSequenceByPageUri(String identifier, String uri);

	/**
	 * Finds sequence by identifier and localizable.
	 *
	 * @param identifier  Identifier of sequence to search by
	 * @param localizable Owner of this sequence
	 * @return Sequence or null if nothing was found
	 */
	public Sequence findSequenceByLocalizable(String identifier, Localizable localizable);
}